/*
 * @Author: Await
 * @Date: 2025-05-10 09:25:00
 * @LastEditors: Await
 * @LastEditTime: 2025-05-10 09:25:00
 * @Description: 图表主题工具函数
 */

import * as echarts from 'echarts';
import { logDebug } from './commonUtils';

/**
 * 注册自定义主题
 * @param theme 主题配置
 * @returns 注册后的主题名称
 */
export const registerTheme = (theme: any): string => {
  if (!theme) return 'default';
  
  // 如果传入的是字符串，认为是已注册的主题名称
  if (typeof theme === 'string') {
    return theme;
  }
  
  // 处理自定义主题对象
  const timestamp = Date.now();
  const themeName = `custom_theme_${timestamp}`;
  
  try {
    echarts.registerTheme(themeName, theme);
    logDebug(`成功注册自定义主题: ${themeName}`);
    return themeName;
  } catch (error) {
    logDebug('注册自定义主题失败:', error);
    return 'default';
  }
};